home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 November / macformat-043.iso / mac / Shareware Plus / Developers / Sprite Animation Toolkit 2.3.8 / Add-ons / Lib ƒ / SATAddOnLib.p < prev   
Encoding:
Text File  |  1996-05-23  |  5.9 KB  |  145 lines  |  [TEXT/PJMM]

  1. {SATAddOnLib is a lib of the "Add-ons" that are easily put in a library (i.e. the ones without}
  2. {a "stubs" file). They include:}
  3. {}
  4. {GammaFade}
  5. {ProgressBar}
  6. {FaceFromPict}
  7. {SATToolbox}
  8. {Preferences}
  9.  
  10. unit SATAddOnLib;
  11. interface
  12.     uses
  13. {$IFC UNDEFINED THINK_PASCAL}
  14.         Types, QuickDraw, Menus, ToolUtils, Resources, {}
  15. {$ENDC}
  16.         SAT;
  17.  
  18. {*** GammaFade ***}
  19. {Screen fading routines.}
  20.  
  21.     procedure FadeToBlack (ticks: Longint);
  22.     procedure FadeFromBlack (ticks: Longint);
  23.  
  24. {*** FaceFromPict ***}
  25. {Load a face from PICTs}
  26.  
  27.     function GetFaceFromPICT (colorPICTid, bwPICTid, maskPICTid: integer): FacePtr;
  28.  
  29. {Pixel array types and routines}
  30.     type
  31.         Pixel = record
  32.                 position: Point;
  33.                 data1, data2, data3, data4: SignedByte;
  34.             end;
  35.         Pixels = array[0..32000] of Pixel;
  36.         PixelPtr = ^Pixels;
  37.  
  38.     procedure SATDrawPixels (pix: PixelPtr; var port: SATPort; value: Longint);
  39.     procedure SATCopyPixels (pix: PixelPtr; var src, dest: SATPort);
  40.     procedure SATDrawPixelsSafe (pix: PixelPtr; var port: SATPort; value: Longint);
  41.     procedure SATCopyPixelsSafe (pix: PixelPtr; var src, dest: SATPort);
  42.  
  43. {*** Preferences ***}
  44. {Create a preference file in the Preferences folder.}
  45.  
  46. {Open the pref file if needed. Return the variables appFile and prefFile.}
  47. {If alwaysExternal is true, we always want a pref file in the system folder even if we can save in the application.}
  48. {Returns true if a new prefFile was created.}
  49.     function SetPrefFile (prefsFileName: Str255; prefCreator, prefType: OSType; var appFile, prefFile: Integer; alwaysExternal: Boolean): Boolean;
  50.  
  51. {Copy a resource from one file to another. Useful when SetPrefFile returns true!}
  52.     function CopyResource (fromFile, toFile: integer; theResType: ResType; id: integer): OSErr;
  53.  
  54. {*** ProgressBar ***}
  55. {An adaptive progress bar, adjusts itself automatically by remembering how much time the}
  56. {time-consuming operation took last time.}
  57.  
  58. {Note: The full type declarations are removed to make this brief. See ProgressBar.p if you need them.}
  59.     type
  60.         ProgressBarColorPtr = Ptr;
  61.         ProgressBarPtr = Ptr;
  62.  
  63.     function InitProgressBar (prefFile, resID: Integer; bounds: Rect; colors: ProgressBarColorPtr): ProgressBarPtr;
  64.     function ProgressBarColors (frameRed, frameGreen, frameBlue, backRed, backGreen, backBlue, foreRed, foreGreen, foreBlue: Integer): ProgressBarColorPtr;
  65.     function ProgressBarColorsRGB (frame, back, fore: RGBColor): ProgressBarColorPtr;
  66.     procedure AdvanceProgressBar (thePB: ProgressBarPtr);
  67.     procedure FinishProgressBar (thePB: ProgressBarPtr);
  68.  
  69. {*** SATToolbox ***}
  70. {Some sprite handling routines, plus some math routines.}
  71.  
  72. {The following switch should be true if your SAT.p has a fixedPointPosition field.}
  73. {MUST MATCH THE FLAG IN SATToolbox.p WHEN THE LIB WAS COMPILED!}
  74. {$setc _hasfixedpoint = true}
  75.  
  76.     type
  77.         FixSpritePtr = ^FixSprite;
  78.         FixSprite = record
  79. { Variables that you should change as appropriate }
  80.                 kind: Integer; { Used for identification. >0: friend. <0 foe }
  81.                 position: Point;
  82.                 hotRect, hotRect2: Rect; { Tells how large the sprite is; hotRect is centered around origo }
  83.                                     {hotRect is set by you. hotRect2 is offset to the current position.}
  84.                 face: FacePtr;            { Pointer to the Face (appearance) to be used. }
  85.                 task: ProcPtr;            { Callback-routine, called once per frame. If task=nil, the sprite is removed. }
  86.                 hitTask: ProcPtr;        { Callback in collisions. }
  87.                 destructTask: ProcPtr;    { Called when a sprite is disposed. (Usually nil.) }
  88.                 clip: RgnHandle;            {Clip region to be used when this sprite is drawn.}
  89. { SAT variables that you shouldn't change: }
  90.                 oldpos: Point;                {Used by RunSAT2}
  91.                 next, prev: SpritePtr;    {You may change them in your own sorting routine, but be careful if you do.}
  92.                 r, oldr: Rect;                {Rectangle telling where to draw. Avoid messing with it.}
  93.                 oldFace: FacePtr;            {Used by RunSAT2}
  94.                 dirty: Boolean;            {Used by RunSAT2}
  95. {Variables for internal use by the sprites. Use as you please. Edit as necessary - this is merely a default}
  96. {set, enough space for most cases - but if you change the size of the record, call SetSpriteSize immediately}
  97. {after initializing (before any sprites are created)!}
  98.                 layer: integer; {For layer-sorting. When not used for that, use freely.}
  99.                 speed: Point; { Can be used for speed, but not necessarily. }
  100.                 mode: integer; { Usually used for different modes and/or to determine what image to show next. }
  101.                 fixedPointPosition: Point; {fixed point position}
  102.                 appLong: Longint; {Longint for free use by the application.}
  103.             end;
  104.  
  105. {Constants for separation/bounceoff between sprites}
  106.     const
  107.         kPushBoth = 0;
  108.         kPushMe = 1;
  109.         kPushHim = 2;
  110.  
  111. (*Sprite utilities*)
  112.     procedure MoveSprite (theSprite: SpritePtr);
  113.     function KeepOnScreen (theSprite: SpritePtr): Boolean;
  114. {$ifc _hasfixedpoint}
  115.     procedure MoveSpriteFixedPoint (theSprite: FixSpritePtr);
  116.     function KeepOnScreenFixed (theSprite: FixSpritePtr): Boolean;
  117. {$endc}
  118.     function RectSeparate (theSprite: SpritePtr; anotherSprite: SpritePtr; push: Integer): Integer;
  119.     procedure RectBounce (me, him: SpritePtr; push: Integer);
  120.     procedure RectBounceFixed (me, him: FixSpritePtr; push: Integer);
  121.     function PtInSpriteRgn (p: Point; theSprite: SpritePtr): Boolean;
  122.     function RegionHit (theSprite: SpritePtr; anotherSprite: SpritePtr): Boolean;
  123.     procedure SplitVector (v: Point; d: Point; var p: Point; var n: Point);
  124.  
  125.     procedure RegionBounce (s1, s2: FixSpritePtr);
  126.  
  127. {*** Look-up table based fixed-point math operations. ***}
  128. {Good for high-speed trig functions on 68k Macs. (Not tested too much yet.)}
  129.  
  130. {Don't change these constants without recompiling the lib!}
  131.     const
  132.         kFixedPointShift = 4; {Number of fixed-point positions}
  133.         kFixedOne = 16; {The "one" in the fixed-point system being used!}
  134.  
  135.     procedure InitTables; {Init not required}
  136.     function SquareRoot (arg: Longint): Longint;
  137.     function Sinus (arg: Longint): Longint;
  138.     function Cosinus (arg: Longint): Longint;
  139.     function VectorLength (vector: Point): Longint;
  140.     function FPVectorLength (vector: Point): Longint;
  141.  
  142.  
  143.  
  144. implementation
  145. end.